<template>
  <div class="bei">
      <BeiTop/>
      <Statu/>
      <CityBanner/>
      <CityText/>
  </div>
</template>

<script>
// import {homelink} from "@/api/homeapi.js";
import BeiTop from "@/components/beiTop.vue";
import Statu from '@/components/statu.vue';
import CityBanner from '@/components/cityBanner.vue';
import CityText from "@/components/cityText.vue";
export default {
    components:{
        BeiTop,
        Statu,
        CityBanner,
        CityText,
    },
    data(){
        return {
            data:{}
        }
    },
    created () {
        //在页面加载时读取localStorage里的状态信息
        if (localStorage.getItem("data") ) {
            //replaceState替换数据 Object.assign合并对象
            this.$store.replaceState(Object.assign({}, this.$store.state,JSON.parse(localStorage.getItem("data"))))
        } 
        //在页面刷新时将vuex里的信息保存到localStorage里
        window.addEventListener("beforeunload",()=>{
            localStorage.setItem("data",JSON.stringify(this.$store.state))
        })
    },
    mounted(){
        let newArr = this.$store.state.arr1;
        newArr.forEach((item)=>{
            item.list.filter((v)=>{
                if(v.id == this.$route.query.id){
                    this.data = v;
                }
            })
        })
        this.$store.commit("xshow",this.data);
    }
}
</script>

<style scoped>

</style>